<script setup>
import { ref } from 'vue'
import { artGetChannelService } from '@/api/article.js'

// 接收父组件传过来的id值
defineProps({
  modelValue: [String, Number],
  // 自己封装组件属性
  width: String
})

const emit = defineEmits(['update:modelValue'])

// 渲染下拉菜单
const channelList = ref([])
const getChannlList = async () => {
  const res = await artGetChannelService()
  channelList.value = res.data.data
}
getChannlList()
</script>
<template>
  <el-select
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue', $event)"
    :style="{ width }"
  >
    <!-- label是展示给用户看的, value是提交给后台辨识的 -->
    <el-option
      v-for="item in channelList"
      :key="item.id"
      :label="item.cate_name"
      :value="item.id"
    ></el-option>
  </el-select>
</template>
